const fn = (s) => {
  if (s.length <= 1) return s.length;
  let max = 0;
  let slow = 0;
  let fast = 0;
  let curArr = new Set();
  console.log(s);
  for (let i = 0; i < s.length; i++) {
    while (curArr.has(s[i])) {
      curArr.delete(s[slow]);
      slow++;
    }
    curArr.add(s[i]);
    fast++;
    max = max > fast - slow ? max : fast - slow;
  }
  return max;
};

console.log(fn("au"));

var lengthOfLongestSubstring = function (s) {
  let slow = 0;
  let fast = 0;
  let max = 0;
  let len = s.length;
  let cur = [];
  for (let i = 0; i < len; i++) {
    if (cur.includes(s[i])) {
      const index = cur.findIndex((item) => item === s[i]);
      cur.splice(0, index + 1);
      slow += index + 1;
    }
    cur.push(s[i]);
    fast++;
    max = fast - slow > max ? fast - slow : max;
  }
  return max;
};
console.log(lengthOfLongestSubstring("bbbabb"));
